Walkthrough 1-2: Make calls to an API
In this walkthrough, you make calls to a RESTful API. You will:
· Use Advanced REST Client to make calls to an unsecured API (an implementation).
· Make GET, DELETE, POST, and PUT calls.
· Use Advanced REST Client to make calls to a secured API (an API proxy).
· Use the API console in an API portal to make calls to a managed API using a mocking service.
· Use the API console to make calls to an API proxy endpoint.
Use Advanced REST Client to make GET requests to retrieve data
1. Return to or open Advanced REST Client.
2. Make sure the method is set to GET.
3. Return to the course snippets.txt file.
4. Copy the URL for the American Flights web service:
http://training4-american-ws.cloudhub.io/api/flights.
Note: This is the URL for the API implementation, not the managed API proxy. The -ws stands for web service.
5. Return to Advanced REST Client and paste the URL in the text box that says Request URL, replacing any existing content.
6. Click the Send button; you should get a response.
7. Locate the return HTTP status code of 200.
8. Review the response body containing flights to SFO, LAX, and CLE.
9. Click the Toggle raw response view (or Toggle source view) button.
10. Click the arrow to the right of the URL.
11. In the detailed editor area that appears, click the Add button.
12. Set the Parameter name to destination and the Parameter value to CLE.
13. Click the Send button; you should get just flights to CLE returned.
14. Click the X next to the parameter to delete it.
15. Click the arrow to the right of the URL to collapse the detailed editor area.
16. Change the request URL to use a URI parameter to retrieve the flight with an ID of 3: http://training4-american-ws.cloudhub.io/api/flights/3.
17. Click
the Send button; you should see only the flight with that ID returned.
Make DELETE requests to delete data
18. Change the method to DELETE.
19. Click the Send button; you should see a 200 response with the message Flight deleted (but not really).
Note: The database is not actually modified so that its data integrity can be retained for class.
20. Remove the URI parameter from the request: http://training4-american-ws.cloudhub.io/api/flights.
21. Click the Send button; you should get a 405 response with the message Method not allowed.
Make a POST request to add data
22. Change the method to POST.
23. Click the Send button; you should get a 415 response with the message Unsupported media type.
24. Click the arrow next to Parameters beneath the request URL.
25. Click Add Header.
26. Click in the Header name field, type Co, and then select Content-Type.
27. Click in the Parameter value field and then select application/json.
28. Select the Body tab.
29. Return to the course snippets.txt file and copy the value for American Flights API post body.
30. Return to Advanced REST Client and paste the code in the body text area.
31. Click the Send button; you should see a 201 Created response with the message Flight added (but not really).
32. Return to the request body and remove the plane field and value from the request body.
33. Remove the comma after the emptySeats key/value pair.
34. Send the request; the message should still post successfully.
35. In the request body, remove the emptySeats key/value pair.
36. Delete the comma after the destination key/value pair.
37. Send the request; you should see a 400 Bad Request response with the message Bad request.
Make a PUT request to update data
38. Change the method to PUT.
39. Add a flight ID of 3 to the URL.
40. Click the Send button; you should get a 400 Bad Request.
41. In the request body field, press Cmd+Z or Ctrl+Z until the emptySeats field is added back.
42. Send the request; you should get a 200 OK response with the message Flight updated (but not really).
Make a request to a secured API
43. Remove the Content-Type header by clicking its Remove this header button.
44. Change the method to GET.
45. Change the request URL to http://training4-american-api.cloudhub.io/flights/3.
Note: The -ws in the URL has been changed to -api and the /api removed.
46. Click the Send button; you should get a 401 Unauthorized response with the message Invalid client id or secret.
47. Return to the course snippets.txt file and copy the value for the American Flights API client_id.
48. Return to Advanced REST Client and add a header called client_id.
49. Set client_id to the value you copied from the snippets.txt file.
50. Return to the course snippets.txt file and copy the value for the American Flights API client_secret.
51. Return to Advanced REST Client and add a second header called client_secret.
52. Set client_secret to the value you copied from the snippets.txt file.
53. Click the Send button; you should get data for flight 3 again.
54. Click the Send button several more times; you should get a 429 Too Many Requests response with the message Quota has been exceeded.
Note: For the self-study training class, the API service level agreement (SLA) for the application with your client ID and secret has been set to allow three API calls per minute while, for the instructor-led class, the SLA allows for a higher number to accommodate shared use.
Use the API console in the API portal to make requests to the API using a mocking service
55. Return to the browser window with the American Flights API portal at https://anypoint.mulesoft.com/exchange/portals/muletraining.
56. In the left-side navigation click the GET method for /flights.
57. Review the Headers and Response sections.
58. In the Response section, look at the output example.
59. In the API console located on the right side of the page, make sure the Mocking Service endpoint is selected.
60. Look at the endpoint URL that is displayed.
61. Select the Show optional parameters checkbox.
62. Select LAX in the destination drop-down menu.
63. Select the Headers tab.
64. Enter any values for client_id and client_secret.
65. Click Send; you should get the example flights that are to SFO and ORD.
Make requests to the API using an API proxy endpoint
66. At the top of the API console, change the endpoint to Production – Rate limiting SLA based policy.
67. Look at the endpoint URL that is displayed.
68. Click Send; you should get a 401 Unauthorized response.
69. Copy and paste the client_id and client_secret values from the course snippets.txt file.
70. Click Send; you should get a 200 OK response with only flights to LAX.